package com.sicilin.common.action;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sicilin.system.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by sicilin on 2017/7/31.
 */
@Controller
@RequestMapping("/pages")
public class JSPAction {

    @Autowired
    private LoginService loginService;

    @RequestMapping(value = "/**/*.jhtml")
    public ModelAndView toJSP(HttpServletRequest request) throws Exception{
        String url = request.getServletPath().substring(7).replace(".jhtml","");
        ObjectMapper mapper = new ObjectMapper();
        ModelAndView modelAndView = new ModelAndView(url,"currentUser",new ObjectMapper().writeValueAsString(loginService.getCurrentUser()));
        return modelAndView;
    }
}
